<template>
  <a-table :columns="conlumns" :data="taskList">
    <template #accept="{ record }">
      <a-button type="outline" size="mini" status="success" @click="acceptTask(record)">抢单</a-button>
    </template>
    <template #type="{ record }">
      <span v-if="record.type === 'AMZ_PIC'">制图 (亚马逊)</span>
      <span v-else>{{ record.type }}</span>
    </template>
  </a-table>
</template>

 


<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { preparedTaskGroupSearch, taskAccept } from '@/api/task'
import { Message } from '@arco-design/web-vue'
let taskList = ref()
let conlumns = [
  {
    title: '类型',
    slotName: 'type',
  },
  {
    title: '状态',
    slotName: 'accept',
  },
  {
    title: '任务',
    dataIndex: 'subject',
  },
  {
    title: '发布人',
    dataIndex: 'creatorUserName',
  },
  {
    title: '备注',
    dataIndex: 'creatorRemarks',
  },
  {
    title: '期望完成时间',
    dataIndex: 'gmtExpectFinish',
  },
  {
    title: '发布时间',
    dataIndex: 'gmtWrite',
  },
]
onMounted(async () => {
  let result = await preparedTaskGroupSearch({})
  taskList.value = result?.data?.records || []
  //alert(JSON.stringify(taskList))
})

const acceptTask = async (task: any) => {
  let rs = await taskAccept({ taskGroupIdList: [task.id] })
  if (!rs?.data?.taskGroupIdList) {
    Message.warning('抢单失败!')
    return
  }
  ;(rs?.data?.taskGroupIdList || []).forEach((groupId: any) => {
    taskList.value.forEach((item: any, index: any) => {
      if (item.id === groupId) {
        taskList.value.splice(index, 1)
      }
    })
  })
  Message.success('抢单成功!')
}
</script> 





 

<style lang="less" scoped></style>